<?php

namespace Common\Model;

/**
 * HotelCouponRoomTypeModel.class.php实例模型
 * 
 * @author wenhui
 * @date 2017-011-09
 */
class HotelCouponDisableDateModel extends BaseModel {

    protected $trueTableName = 'bk_hotel_coupon_disable_date';

    protected function _before_insert(&$data, $options) {
    }

    protected function _before_update(&$data, $options) {
    }

    /**
     * 添加数据
     * @modify wenhui 2018-01-02
     * @param integer $name  服务名称
     * @return type
     */
    public function addCouponDisableDate($data) {
        return $this->addAll($data);
    }

    /**
     * 获取数据
     * @modify wenhui 2017-01-02    创建
     * @param  int   $couponIds    ID
     * @param  bool   $isDelete 是否获取删除记录
     * @return data
     */
    public function getCouponDisableDate($couponIds, $isDelete = false) {
        if (is_array($couponIds)) {
            $couponIds = implode(',', $couponIds);
        }

        if (strpos($couponIds, ',') !== false) {
            $option['coupon_id'] = array('in', $couponIds);
        } else {
            $option['coupon_id'] = $couponIds;
        }

        if (!$isDelete) {
            $option['isdelete'] = NOT_DELETE;
        }

        $field = 'id,coupon_id,date';
        $data = $this->where($option)->field($field)->select();

        return empty($data) ? array() : $data;
    }

    /**
     * 保存数据
     * @modify wenhui 2018-01-02
     * @param integer $name  服务名称
     * @return type
     */
    public function saveInfo($serverId, $name) {
        $data = array();

        $options['id'] = $serverId;
        $data['name'] = $name;

        return $this->where($options)->save($data) === false ? false : true;
    }


    /**
     * 获取数据
     * @modify wenhui 2018-01-02
     * @param integer $couponId  优惠券ID
     * @return type
     */
    public function getDateByCouponId($couponId) {

        $options['coupon_id'] = $couponId;
        $options['isdelete'] = NOT_DELETE;

        $field = 'id,date';
        $data = $this->field($field)->where($options)->select();

        return !empty($data) ? $data : array();
    }

    /**
     * 修改数据
     * @modify wenhui 2018-01-02
     * @param integer $id  id
     * @param integer $isdelete  
     * @return type
     */
    public function editCouponDisableDate($id, $isdelete = null) {
        $data = array();

        $options['id'] = $id;

        if (!is_null($isdelete)) {
            $data['isdelete'] = $isdelete;
        }

        return $this->where($options)->save($data) === false ? false : true;
    }

    /**
     * 删除
     * @modify wenhui 2018-01-02
     * @param  int   $couponId    ID
     * @return type
     */
    public function deleteCouponDisableDate($couponId) {
        $data = array();

        $options['coupon_id'] = $couponId;
        $data['isdelete'] = IS_DELETE;

        return $this->where($options)->save($data) === false ? false : true;
    }
}
